/******************************************************************************
 * The contents of this file are subject to the   JDI License  Version 1.0
 * ("License"); You may not use this file except in compliance with the License
 * Software distributed under the License is distributed on an  "AS IS"  basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 * The Initial Developer of the Original Code is 陈慧然. Portions created by 
 * 陈慧然 are Copyright 陈慧然.
 * All Rights Reserved.
 *
 *              Contact john_holen@163.com for licensing alternatives.
 *
 *****************************************************************************/


package org.peony.client.web.components.table;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.peony.client.web.components.WebComponents;
import org.peony.exceptions.RenderException;
import org.peony.tools.StringUtil;

/**
 *  
 *
 *  @author     陈慧然
 *  @version    Id: THead.java, v 0.000 2008-4-25 下午04:53:06 陈慧然 Exp
 */
public class THead extends WebComponents{
	private List<Th> ths = new ArrayList<Th>();
	
	public List<Th> getThs(){
		return ths;
	}
	
	public void setThs(List<Th> ths){
		this.ths = ths;
	}
	
	public void putATh(Th th){
		ths.add(th);
	}
	
	public void putATh(int index,Th th){
		ths.add(index,th);
	}
	
	public String toStandardString() throws RenderException {
		if(StringUtil.isEmpty(getId()))
			throw new RenderException("THead (A Component) Can NOT has no id!");
		StringBuffer sb = new StringBuffer();
		sb.append("<thead ").append("id= \"").append(getId()).append("\"")
			.append(StringUtil.isNotEmpty(getUIClass())?" class=\"" + getUIClass() + "\"><tr>" : "><tr>");
		if(getThs() != null){
			List<Th> alist = getThs();
			for (Iterator<Th> iterator = alist.iterator(); iterator.hasNext();) {
				Th th = iterator.next();
				sb.append(th.toStandardString());
			}
		}
		sb.append("</tr></thead>");
		return sb.toString();
	}
}
